package projetsia.com.hairhunter;

import android.content.Context;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;


public class MyFavorisArrayAdapter extends ArrayAdapter<Favoris> {
    private final Context context;
    private final List<Favoris> values;
    private int color;

    public MyFavorisArrayAdapter(Context context, List<Favoris> values) {
        super(context, R.layout.rowlayout_complex, values);
        this.context = context;
        this.values = values;
        color = context.getResources().getColor(android.R.color.holo_blue_bright);
    }

    @Override
    public int getViewTypeCount() {
        return 2;
    }

    @Override
    public int getItemViewType(int position) {
        return position % 2;
    }

    public static class ViewHolder {
        public TextView t;
        public TextView t2;
        public ImageView i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View rowView = null;

        if (convertView != null) {
            rowView = convertView;
        } else {
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        //    rowView = inflater.inflate(R.layout.rowlayout_complex, parent, false);
            rowView = inflater.inflate(R.layout.rowlayout_complex, parent, false);

            TextView textView = (TextView) rowView.findViewById(R.id.firstLine);
            TextView textView2 = (TextView) rowView.findViewById(R.id.secondLine);
            ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
            ViewHolder holder = new ViewHolder();
            holder.t = textView;
            holder.t2 = textView2;
            holder.i = imageView;
            rowView.setTag(holder);

        }
        ViewHolder tag = (ViewHolder) rowView.getTag();

        String nom = values.get(position).getName();
        String addresse = values.get(position).getAddress();

        System.out.println("Nom : "+nom +" Addresse : "+addresse);
        tag.t.setText(nom);
        tag.t2.setText(addresse);

       /* tag.t.setText(values.get(position).getName().toUpperCase()
                + " Android rules"); */
        // Change the icon for Windows and iPhone

    /*    if (values.get(position).isSelected()) {
            tag.i.setImageResource(R.drawable.ok);
        } else {
            tag.i.setImageResource(R.drawable.no);
        }  */

        rowView.setBackgroundColor(color);
        return rowView;
    }
}
